package com.dz.scrm.mvp.model.entity

import com.dz.scrm.mvp.model.api.CODE_REQUEST_SUCCESS
import com.flyco.tablayout.listener.CustomTabEntity
import org.litepal.crud.LitePalSupport
import java.io.Serializable

/**
 * 作者：fanda
 * 日期：2021/4/21 18:52
 * 描述：
 */

// 所有响应数据的基类
open class BaseResponse<T>(val data: T, val code: Int = 0, val msg: String? = "", val success: Boolean = false) : Serializable {
    fun isSuccess() = code == CODE_REQUEST_SUCCESS
}

// User 实体类
data class User(val id: Int, val login: String? = "", val avatar_url: String? = "") {

    fun getAvatarUrl() = if (avatar_url.isNullOrEmpty()) avatar_url else avatar_url.split("\\?")[0]
}

data class TestParams(val take: String, val stage: String, val grade: String, val skip: String)

data class MsgCodeBean(val result_status: Boolean? = false, val error_code: Int? = 0, val error_description: String? = "")

data class LoginBean(val result_status: Boolean? = false, val error_code: Int? = 0,
                     val error_description: String? = "", val verify: String? = "",
                     var phoneNum: String? = "",
                     val list: List<LoginCompanyBean>? = listOf()) : Serializable

data class LoginCompanyBean(val tenantId: String? = "", val name: String? = "", val customerName: String? = "") : Serializable


data class CompanyInfoBean(val user_id: String? = "", val user_name: String? = "",
                           val tenant_id: String? = "", var account: String? = "",
                           val real_name: String? = "", val role_name: String? = "",
                           val avatar: String? = "", val tenant_simple_name: String? = "",
                           val is_hidden: Boolean? = false, val expires_in: String? = "",
                           val token_type: Boolean? = false, val refresh_token: String? = "",
                           val access_token: String? = "", val error_code: Int? = 0,
                           val error_description: String? = "") : Serializable

data class TestResponse(val weikeId: Int)

data class CheckVersionBean(val version: String? = "", val address: String? = "", val upgrade: Boolean? = false, val userAgreement: String? = "", val privacyAgreement: String? = "", val versionNo: Int = 1) : Serializable

class TabEntity(private val title: String, private val selectedIcon: Int = 0, private val unSelectedIcon: Int = 0) : CustomTabEntity {
    override fun getTabUnselectedIcon() = unSelectedIcon
    override fun getTabSelectedIcon() = selectedIcon
    override fun getTabTitle() = title
}

data class DZResponse(val result_status: Boolean? = false)

open class CachePhoneRecord(var user_id: String = "", var tenant_id: String = "", var showPhoneNum: Boolean = true,
                            var userName: String = "", var phoneDurationTime: Int = 0, var ringDurationTime: Long = 0L, var phoneRingTime: Long = 0L
                            , var phoneStartTime: Long = 0L, var phoneEndTime: Long = 0L, var phoneCallType: Int = 0, var phoneStatus: Int = 0, var uid: String = ""
                            , var fileType: String = "mp3", var customerPhone: String = "", var userPhone: String = "", var phoneOperator: Int = 0, var relegation: String = ""
                            , var phoneType: Int = 1, var fileUrl: String = "", var isDisagree: Boolean = false, var size: Int = 1) : LitePalSupport(), Serializable {

    fun isConnect() = phoneStatus == 1
    fun isInCall() = phoneCallType == 4

    // 打出未接
    fun outWait() = !isInCall() && !isConnect()

    // 打进未接
    fun inWait() = isInCall() && !isConnect()

    // 打进已接
    fun inAccept() = isInCall() && isConnect()

    // 打出已接
    fun outAccept() = !isInCall() && isConnect()

}

open class CacheAllPhoneRecord : CachePhoneRecord() {
    fun copy(record: CachePhoneRecord) {
        this.user_id = record.user_id
        this.tenant_id = record.tenant_id
        this.showPhoneNum = record.showPhoneNum
        this.userName = record.userName
        this.phoneDurationTime = record.phoneDurationTime
        this.ringDurationTime = record.ringDurationTime
        this.phoneRingTime = record.phoneRingTime
        this.phoneStartTime = record.phoneStartTime
        this.phoneEndTime = record.phoneEndTime
        this.phoneCallType = record.phoneCallType
        this.phoneStatus = record.phoneStatus
        this.uid = record.uid
        this.customerPhone = record.customerPhone
        this.fileType = record.fileType
        this.userPhone = record.userPhone
        this.phoneOperator = record.phoneOperator
        this.relegation = record.relegation
        this.phoneType = record.phoneType
        this.fileUrl = record.fileUrl
        this.isDisagree = record.isDisagree
        this.size = record.size
    }
}

class CacheWaitPhoneRecord : CacheAllPhoneRecord()






